.pc = * "Sprite Routines"

.macro SetupSprite(index, address)
{    
    lda #<[address/64]
    sta $c3f8+index

    // set up sprite color
    lda address+63
    sta $d027+index

    ldx #[1<<index]

    jsr setup_sprite
}

setup_sprite:
{
.label bitmask = zero_page_start
    
    // test multicolor flag
    and #$80
    beq clear_multicolor

    // set multicolor flag
    txa
    ora $d01c
    sta $d01c
    rts

clear_multicolor:
    // clear multicolor flag
    txa
    eor #$ff
    and $d01c
    sta $d01c
    rts
}
    
.macro SetSpritePos(index, x, y)
{
    :SetSpriteX(index,x)
    :SetSpriteY(index,x)
}

.macro SetSpriteX(index, x)
{
    lda x
    sta $d000+2*index
    lda $d010
    and #[$ff-[1<<index]]
    sta $d010
}
    
.macro SetSpriteXPlus256(index, x)
{
    lda x
    sta $d000+2*index
    lda $d010
    ora #[1<<index]
    sta $d010
}

.macro SetSpriteY(index, y)
{
    lda y
    sta $d001+2*index
}

.macro EnableSprite(index)
{
    lda $d015
    ora #[1<<index]
    sta $d015
}

.macro DisableSprite(index)
{
    lda $d015
    and #[$ff-[1<<index]]
    sta $d015
}